<?php
require (dirname(__FILE__) . '/config/config.inc.php');
require (dirname(__FILE__) . '/classes/Db.php');


if ($_SERVER["REQUEST_METHOD"] == "POST") {
	session_start();
		$db = new DB();

		$id = $db->login($_POST['username'],$_POST['password'],$_POST['from']);
	
		if($id){
		$response = '{ "response":"success" }';

		// if ($count >= 1) {
			// $response .= ', "achievements" : [';
		// }
		// while ($row = mysql_fetch_assoc($result)) {
			// $response .= json_encode($row) . ",";
		// }
		// $response = substr($response, 0, -1);
		// $response .= '] }';
		// SELECT a.* FROM user_achievement AS ua
		// JOIN achievement AS a ON ua.id_archievement = a.id WHERE ua.id_user = 1

		// SELECT * FROM pre_achievement
		// JOIN pre_achievement_lang AS lang ON pre_achievement.id_message  = lang.id
		// JOIN pre_category AS category ON pre_achievement.id_category = category.id
		// JOIN pre_category_lang AS category_lang ON category_lang.id_category = category.id WHERE category_lang .id_lang = 2 AND lang.id_lang = 2

		echo $response;
	} else {
		echo $response = '{ "response":"fail", "message": "Your Login Name or Password is invalid"}';
	}
}
?>